/**
 * @Project HGEMS
 * @Author Tran Manh Hung
 * @Email: hungtmit@gmail.com | tmh@xwebgate.com
 * @Copyright © 2010 TMH. All rights reserved
 * @Createdate Oct 7, 2010
 * @Createtime 11:02:02 AM
 */


package services
{
	import mx.collections.XMLListCollection;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.mxml.HTTPService;


	public class FuncNavService extends HTTPService
	{

		[Bindable]
		public var funcgroups:XMLListCollection;

		[Bindable]
		public var funcs:XMLListCollection;

		private var funcgroupName:String = "";

		public function FuncNavService(funcgroupName:String = "", rootURL:String = null, destination:String = null)
		{
			super(rootURL, destination);
			this.resultFormat = "e4x";
			this.url = "assets/xmls/hgFuncNav.xml";
			this.funcgroupName = funcgroupName;

			addEventListener(ResultEvent.RESULT, resultHandler);
		}

		protected function resultHandler(event:ResultEvent):void
		{
			if(funcgroupName)
			{
				funcgroups = new XMLListCollection(event.result.funcgroup.(@id == funcgroupName));
				funcs = new XMLListCollection(event.result.funcgroup.(@id == funcgroupName).func);
			}
			else
			{
				funcgroups = new XMLListCollection(event.result.funcgroup);
				funcs = new XMLListCollection(event.result.funcgroup.func);
			}
		}
	}
}